<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
		<script type="text/javascript">
			function fun() {
				/**************验证非空******************/
				var t1 = document.getElementById("t1").value
				if (t1 == "") {
					document.getElementById("s1").innerHTML = "姓名不能为空"
					return false
				} else {
					document.getElementById("s1").innerHTML = "通过"
				}
				/**************验证长度******************/
				var t2 = document.getElementById("t2").value
				if (t2.length < 6) {
					document.getElementById("s2").innerHTML = "密码长度不足六位"
					return false
				} else {
					document.getElementById("s2").innerHTML = "通过"
				}
				/**************验证数字******************/
				var t3 = document.getElementById("t3").value
				if (isNaN(t3) || t3 <= 0 || t3 >= 150) {
					document.getElementById("s3").innerHTML = "年龄必须为0-150"
					return false
				} else {
					document.getElementById("s3").innerHTML = "通过"
				}
				/***************复杂验证（正则）*****************/
				var t4 = document.getElementById("t4").value
				var reg = /^1[0-9]{10}$/
				if (!reg.test(t4)) {
					document.getElementById("s4").innerHTML = "号码错误"
					return false
				} else {
					document.getElementById("s4").innerHTML = "通过"
				}
				return true
			}
		</script>
	</head>
	<body>
		<form action="" method="post" onsubmit="return fun()">
			姓名:<input type="text" id="t1" /><span id="s1"></span><br>
			密码:<input type="password" id="t2" /><span id="s2"></span><br>
			年龄:<input type="text" id="t3" /><span id="s3"></span><br>
			手机:<input type="text" id="t4" /><span id="s4"></span><br>
			<input type="submit" value="提交" />
		</form>
	</body>
</html>
